import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class RequestMapper<T> {
	private T instance;

	public RequestMapper(Class<T> type) throws IllegalArgumentException,
			SecurityException, InstantiationException, IllegalAccessException,
			InvocationTargetException, NoSuchMethodException {
		instance = (T) type.getConstructor(null).newInstance(null);
	}

	public T getObject() {
		return this.instance;
	}

	private Field[] getFields() {
		return instance.getClass().getDeclaredFields();
	}

	private Field[] setAccessPosible() {
		Field[] fields = getFields();
		for (Field field : fields) {
			field.setAccessible(true);
		}
		return fields;
	}

	public void initStringField() throws IllegalArgumentException,
			IllegalAccessException {
		for (Field field : setAccessPosible()) {
			if (field.getType() == String.class && field.get(instance) == null) {
				field.set(instance, "");
			}
		}
	}

	private void setField(String fieldName, Object value)
			throws IllegalArgumentException, SecurityException,
			IllegalAccessException, NoSuchFieldException {
		Field[] fields = setAccessPosible();
		for (Field field : fields) {
			if (field.getName().equals(fieldName)) {
				field.set(instance, value);
			}
		}
	}

}
